package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspSector;
import cn.xscrum.vtsp.service.IVtspSectorService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 部门信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/sector")
public class VtspSectorController extends BaseController
{
    private String prefix = "vtsp/sector";

    @Autowired
    private IVtspSectorService vtspSectorService;

    @RequiresPermissions("vtsp:sector:view")
    @GetMapping()
    public String sector()
    {
        return prefix + "/sector";
    }

    /**
	 * 查询部门信息列表
     */
    @RequiresPermissions("vtsp:sector:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspSector vtspSector)
    {
        startPage();
        List<VtspSector> list = vtspSectorService.selectVtspSectorList(vtspSector);
        return getDataTable(list);
    }

    /**
	 * 导出部门信息列表
     */
    @RequiresPermissions("vtsp:sector:export")
    @Log(title = "部门信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspSector vtspSector)
    {
        List<VtspSector> list = vtspSectorService.selectVtspSectorList(vtspSector);
        ExcelUtil<VtspSector> util = new ExcelUtil<VtspSector>(VtspSector.class);
        return util.exportExcel(list, "sector");
    }

    /**
	 * 新增部门信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存部门信息
     */
    @RequiresPermissions("vtsp:sector:add")
    @Log(title = "部门信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspSector vtspSector)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspSector);
        return toAjax(vtspSectorService.insertVtspSector(vtspSector));
    }

    /**
	 * 修改部门信息
     */
    @GetMapping("/edit/{sectorId}")
    public String edit(@PathVariable("sectorId") Long sectorId, ModelMap mmap)
    {
        VtspSector vtspSector = vtspSectorService.selectVtspSectorById(sectorId);
        mmap.put("vtspSector", vtspSector);
        return prefix + "/edit";
    }

    /**
	 * 修改保存部门信息
     */
    @RequiresPermissions("vtsp:sector:edit")
    @Log(title = "部门信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspSector vtspSector)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspSector);
        return toAjax(vtspSectorService.updateVtspSector(vtspSector));
    }

    /**
	 * 删除部门信息
     */
    @RequiresPermissions("vtsp:sector:remove")
    @Log(title = "部门信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + ids);
        return toAjax(vtspSectorService.deleteVtspSectorByIds(ids));
    }
}
